package com.jz.community.modulemine.ui.activity;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.Keyframe;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Point;
import android.graphics.drawable.AnimationDrawable;
import android.support.v7.widget.Toolbar;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.gyf.barlibrary.ImmersionBar;
import com.jakewharton.rxbinding2.view.RxView;
import com.jz.community.basecomm.base.BaseMvpActivity;
import com.jz.community.basecomm.base.BaseX5WebActivity;
import com.jz.community.basecomm.glideConfig.GlideApp;
import com.jz.community.basecomm.routerUtils.RouterCommonUtils;
import com.jz.community.basecomm.routerUtils.RouterIntentConstant;
import com.jz.community.basecomm.task.ITaskCallbackListener;
import com.jz.community.basecomm.utils.BaseImageLoaderUtils;
import com.jz.community.basecomm.utils.BaseSpUtils;
import com.jz.community.basecomm.utils.LoggerUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.basecomm.utils.RxDataTool;
import com.jz.community.basecomm.utils.RxTextTool;
import com.jz.community.basecomm.utils.WXUtils;
import com.jz.community.basecomm.utils.WpToast;
import com.jz.community.basecomm.utils.eventbus.AppEvent;
import com.jz.community.basecomm.utils.eventbus.EventConfig;
import com.jz.community.commview.callback.ErrorCallback;
import com.jz.community.commview.callback.LoadingCallback;
import com.jz.community.modulemine.R;
import com.jz.community.modulemine.R2;
import com.jz.community.modulemine.bean.SignAwardBean;
import com.jz.community.modulemine.bean.SignDataBean;
import com.jz.community.modulemine.bean.SignResultBean;
import com.jz.community.modulemine.mySgn.SignAdvInfo;
import com.jz.community.modulemine.mySgn.SignAdvTask;
import com.jz.community.modulemine.presenter.SignPresenter;
import com.jz.community.modulemine.ui.SignView;
import com.jz.community.modulemine.ui.view.ChestDialog;
import com.jz.community.commview.view.numberTextView.NumberRunningTextView;
import com.jz.community.modulemine.ui.view.WinningCouponDialog;
import com.kingja.loadsir.callback.Callback;
import com.kingja.loadsir.core.LoadService;
import com.kingja.loadsir.core.LoadSir;
import com.orhanobut.logger.Logger;
import com.qmuiteam.qmui.util.QMUIDisplayHelper;

import org.greenrobot.eventbus.EventBus;

import java.util.List;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Admin on 2018/3/30 0030.
 */
@Route(path = RouterIntentConstant.SIGN)
public class SignActivity extends BaseMvpActivity<SignView.View, SignPresenter> implements SignView.View {

    @BindView(R2.id.sign_back)
    ImageView signBack;
    @BindView(R2.id.sign_title)
    TextView signTitle;
    @BindView(R2.id.sign_detail)
    TextView signDetail;
    @BindView(R2.id.sign_toolbar)
    Toolbar signToolbar;
    @BindView(R2.id.sign_banner)
    ImageView signBanner;
    @BindView(R2.id.sign_banner2)
    ImageView signBanner2;
    @BindView(R2.id.sign_points)
    NumberRunningTextView signPoints;
    @BindView(R2.id.sign_mid_ll)
    LinearLayout signMidLl;
    @BindView(R2.id.sign_btn)
    TextView signBtn;
    @BindView(R2.id.sign_mid_parent)
    RelativeLayout signMidParent;
    @BindView(R2.id.sign_days)
    TextView signDays;
    @BindView(R2.id.sign_iv_loc)
    ImageView signIvLoc;
    @BindView(R2.id.sign_loc_ll)
    LinearLayout signLocLl;
    @BindView(R2.id.sign_iv_gift)
    ImageView signIvGift;
    @BindView(R2.id.sign_pb)
    ProgressBar signPb;
    @BindView(R2.id.sign_c1)
    ImageView signC1;
    @BindView(R2.id.sign_c2)
    ImageView signC2;
    @BindView(R2.id.sign_c3)
    ImageView signC3;
    @BindView(R2.id.sign_c4)
    ImageView signC4;
    @BindView(R2.id.sign_c5)
    ImageView signC5;
    @BindView(R2.id.sign_c6)
    ImageView signC6;
    @BindView(R2.id.sign_c7)
    ImageView signC7;
    @BindView(R2.id.sign_tv1)
    TextView signTv1;
    @BindView(R2.id.sign_tv2)
    TextView signTv2;
    @BindView(R2.id.sign_tv3)
    TextView signTv3;
    @BindView(R2.id.sign_tv4)
    TextView signTv4;
    @BindView(R2.id.sign_tv5)
    TextView signTv5;
    @BindView(R2.id.sign_tv6)
    TextView signTv6;
    @BindView(R2.id.sign_tv7)
    TextView signTv7;
    @BindView(R2.id.sign_goods_img1)
    ImageView signGoodsImg1;
    @BindView(R2.id.sign_tag_img1)
    ImageView signTagImg1;
    @BindView(R2.id.sign_red_img1)
    ImageView signRedImg1;
    @BindView(R2.id.sign_goods_img2)
    ImageView signGoodsImg2;
    @BindView(R2.id.sign_tag_img2)
    ImageView signTagImg2;
    @BindView(R2.id.sign_red_img2)
    ImageView signRedImg2;
    @BindView(R2.id.sign_goods_img3)
    ImageView signGoodsImg3;
    @BindView(R2.id.sign_tag_img3)
    ImageView signTagImg3;
    @BindView(R2.id.sign_red_img3)
    ImageView signRedImg3;
    @BindView(R2.id.sign_scroll)
    ScrollView signScroll;

    private LoadService loadService;

    //第几天
    private int day;
    private int count = 0;
    //距离
    private int distance = 0;

    //根据第几天进度条移动进度的数组
    private int days[] = {50, 100, 100, 100, 100, 100, 150};
    private int distances[] = {0, 250, 750, 1250, 1750, 2250, 2750, 3250};

    //屏幕宽度
    private int screen_width;
    //屏幕高度
    private int screen_height;
    //定位图标移动的距离
    private int loc_distance;
    //今天是否已签到
    private int isSign;
    //礼物是否已领取
    private int isDraw;

    private List<SignDataBean.PrizeListBean> sign_goods_list;
    private WinningCouponDialog giftDialog;
    private CompositeDisposable compositeDisposable;
    private List<SignAdvInfo> signAdvInfo;

    private ShareSignPopUp shareSignPopUp;

    @Override
    protected int getContentView() {
        return R.layout.module_mine_activity_sign;
    }

    @Override
    protected SignPresenter createPresenter() {
        return new SignPresenter(this);
    }

    @Override
    public Context getContext() {
        return this;
    }

    @SuppressLint("CheckResult")
    @Override
    protected void initView() {
        ImmersionBar.with(this)
                .titleBar(signToolbar)
                .statusBarDarkFont(true, 0.2f)//当白色背景状态栏遇到不能改变状态栏字体为深色的设备时，解决方案
                .init();

        signTitle.setText("每日签到");

        loadService = LoadSir.getDefault().register(signScroll, (Callback.OnReloadListener) v -> {
            if (loadService.getCurrentCallback() == ErrorCallback.class) {
                loadService.showCallback(LoadingCallback.class);
                mPresenter.initSignData();
            }
        });

        loadService.setCallBack(ErrorCallback.class, (context, view) -> {
            ImageView mIvError = (ImageView) view.findViewById(R.id.error_img);
            mIvError.setImageResource(R.mipmap.error_default);
        });

        loadService.setCallBack(LoadingCallback.class, (context, view) -> {
            ImageView mIvLoading = (ImageView) view.findViewById(R.id.loading_img);
            GlideApp.with(SignActivity.this)
                    .asGif()
                    .load(R.drawable.loading_default)
                    .into(mIvLoading);

        });

        //获取屏幕宽高
        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        screen_width = size.x;
        screen_height = size.y;

        //Banner 2:1
        ViewGroup.LayoutParams lp_banner = signBanner.getLayoutParams();
        lp_banner.height = screen_width / 2;
        signBanner.setLayoutParams(lp_banner);
        ViewGroup.LayoutParams lp_banner2 = signBanner2.getLayoutParams();
        lp_banner.height = screen_width / 2;
        signBanner2.setLayoutParams(lp_banner2);
        loc_distance = (screen_width - QMUIDisplayHelper.dp2px(this, 20)) / 7;
        mPresenter.initSignData();
        getSignAdvData();

        RxView.clicks(signBtn)
                .throttleFirst(1, TimeUnit.SECONDS)   //两秒钟之内只取一个点击事件，防抖操作
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object o) throws Exception {
                        if (day >= 7) {
                            return;
                        }

                        String userId = BaseSpUtils.getInstance().getUserId(mActivity) + "";
                        mPresenter.clickSign(userId);
                    }
                });


    }

    /**
     * 签到广告图
     */
    private void getSignAdvData() {
        new SignAdvTask(this, new ITaskCallbackListener() {
            @Override
            public void doTaskComplete(Object o) {
                signAdvInfo = (List<SignAdvInfo>) o;
                if (!Preconditions.isNullOrEmpty(signAdvInfo)) {
                    //底部广告图
                    if (!RxDataTool.isNullString(signAdvInfo.get(0).getImages())) {
                        BaseImageLoaderUtils.getInstance().loadDefaltImage(SignActivity.this, signBanner2, signAdvInfo.get(0).getImages());
                    }
                }
            }
        }).execute();
    }

    @Override
    public void setSignData(SignDataBean entity) {
        loadService.showSuccess();
        //积分
        if (!Preconditions.isNullOrEmpty(entity.getUser())){
            signPoints.setContent(entity.getUser().getResidualIntegral());
        }

        //签到状态
        BaseSpUtils.getInstance().setIsSign(this, true);


        if (!RxDataTool.isNullString(entity.getSignCount())) {
            day = Integer.parseInt(entity.getSignCount());
            signDays.setText("已连续签到" + day + "天");
            distance = distances[day];
            if (day >= 2 && day < 7) {
                locAnimatorFirst();
            }
            if (day < 7) {
                signPb.setProgress(distance);
            } else {
                signPb.setProgress(3500);
            }
        }

        if (!RxDataTool.isNullString(entity.getStatus())) {
            //今天是否已签到
            isSign = Integer.parseInt(entity.getStatus());
            if (isSign == 0) {
                //未签到
                signBtn.setBackgroundResource(R.drawable.button_border_home);
                signBtn.setText("今日签到");
                signBtn.setEnabled(true);

            } else if (isSign == 1) {
                //已签到
                signBtn.setBackgroundResource(R.drawable.button_border_home_gray);
                signBtn.setText("已签到");
                signBtn.setEnabled(false);
            }
        }

        if (!RxDataTool.isNullString(entity.getBoxStatus())) {
            isDraw = Integer.parseInt(entity.getBoxStatus());
            if (isDraw == 0) {
                //未领取
                signIvGift.setImageResource(R.mipmap.sign_gift);
                signIvGift.setEnabled(true);

            } else if (isDraw == 1) {
                //已领取
                signIvGift.setImageResource(R.mipmap.sign_gift_gray);
                signIvGift.setEnabled(false);
            }
        }

        sign_goods_list = entity.getPrizeList();
        if (null != sign_goods_list) {
            if (sign_goods_list.size() >= 3) {
                //限时购图片大小，防止OOM
                int img_width = (screen_width - QMUIDisplayHelper.dp2px(SignActivity.this, 40)) / 3;

                ViewGroup.LayoutParams lp_img1 = signGoodsImg1.getLayoutParams();

                lp_img1.width = img_width;
                lp_img1.height = img_width;
                signGoodsImg1.setLayoutParams(lp_img1);

                ViewGroup.LayoutParams lp_img2 = signGoodsImg2.getLayoutParams();

                lp_img2.width = img_width;
                lp_img2.height = img_width;
                signGoodsImg2.setLayoutParams(lp_img2);

                ViewGroup.LayoutParams lp_img3 = signGoodsImg3.getLayoutParams();

                lp_img3.width = img_width;
                lp_img3.height = img_width;
                signGoodsImg3.setLayoutParams(lp_img3);

                BaseImageLoaderUtils.getInstance().loadDefaltImage(SignActivity.this, signGoodsImg1, sign_goods_list.get(0).getImage());

                BaseImageLoaderUtils.getInstance().loadDefaltImage(SignActivity.this, signGoodsImg2, sign_goods_list.get(1).getImage());

                BaseImageLoaderUtils.getInstance().loadDefaltImage(SignActivity.this, signGoodsImg3, sign_goods_list.get(2).getImage());

            }

            if (day >= 7) {
                for (int i = 0; i < sign_goods_list.size(); i++) {
                    if (sign_goods_list.get(i).getChecked() == 1) {
                        if (i == 0) {
                            signTagImg1.setVisibility(View.VISIBLE);
                        } else if (i == 1) {
                            signTagImg2.setVisibility(View.VISIBLE);
                        } else if (i == 2) {
                            signTagImg3.setVisibility(View.VISIBLE);
                        }
                    }
                }
            }
        }

        if (day >= 1) {
            signRedImg1.setVisibility(View.GONE);
        }
        if (day >= 4) {
            signRedImg2.setVisibility(View.GONE);
        }
        if (day >= 7) {
            signRedImg3.setVisibility(View.GONE);
        }

        initSign();
    }

    @Override
    public void clickSignSuccess(SignResultBean entity) {
        signPoints.setText(entity.getUser().getResidualIntegral() + "");
        if (!RxDataTool.isNullString(entity.getSignCount())) {
            signDays.setText("已连续签到" + entity.getSignCount() + "天");
            if (day >= 1) {
                locAnimator();
            }
            startTime(days[day]);
            day++;
        }

        if (!RxDataTool.isNullString(entity.getStatus())) {
            //今天是否已签到
            isSign = Integer.parseInt(entity.getStatus());
            if (isSign == 0) {
                //未签到
                signBtn.setBackgroundResource(R.drawable.button_border_home);
                signBtn.setText("今日签到");
                signBtn.setEnabled(true);

            } else if (isSign == 1) {
                //已签到
                signBtn.setBackgroundResource(R.drawable.button_border_home_gray);
                signBtn.setText("已签到");
                signBtn.setEnabled(false);
            }
        }
        if (!RxDataTool.isNullString(entity.getBoxStatus())) {
            isDraw = Integer.parseInt(entity.getBoxStatus());
            if (isDraw == 0) {
                //未领取
                signIvGift.setImageResource(R.mipmap.sign_gift);
                signIvGift.setEnabled(true);

            } else if (isDraw == 1) {
                //已领取
                signIvGift.setImageResource(R.mipmap.sign_gift_gray);
                signIvGift.setEnabled(false);
            }
        }
        if (day >= 1) {
            signRedImg1.setVisibility(View.GONE);
        }
        if (day >= 4) {
            signRedImg2.setVisibility(View.GONE);
        }
        if (day >= 7) {
            signRedImg3.setVisibility(View.GONE);
        }

        EventBus.getDefault().post(new AppEvent(EventConfig.REFRESH_SIGN));
    }

    @Override
    public void showSignAward(SignAwardBean entity) {
        dismissLoading();
        openGiftDialog(entity);
        signIvGift.setImageResource(R.mipmap.sign_gift_gray);
        signIvGift.setEnabled(false);

        if (null != sign_goods_list) {
            if (sign_goods_list.size() > 0) {
                for (int i = 0; i < sign_goods_list.size(); i++) {
                    if (sign_goods_list.get(i).getChecked() == 1) {
                        if (i == 0) {
                            signTagImg1.setVisibility(View.VISIBLE);
                        } else if (i == 1) {
                            signTagImg2.setVisibility(View.VISIBLE);
                        } else if (i == 2) {
                            signTagImg3.setVisibility(View.VISIBLE);
                        }
                    }
                }
            }
        }

    }

    @Override
    public void setSignFail(String msg) {
        loadService.showCallback(ErrorCallback.class);

    }

    @Override
    public void clickSignFail(String msg) {


    }

    @Override
    public void signAwardError(String msg) {
        showNormal(msg);

    }

    private void initSign() {
        if (distance >= 250) {
            signC1.setBackgroundResource(R.drawable.sign_c_red);
            signTv1.setTextColor(getResources().getColor(R.color.home_red));
            signLocLl.setVisibility(View.VISIBLE);
        }
        if (distance >= 750) {
            signC2.setBackgroundResource(R.drawable.sign_c_red);
            signTv2.setTextColor(getResources().getColor(R.color.home_red));
        }
        if (distance >= 1250) {
            signC3.setBackgroundResource(R.drawable.sign_c_red);
            signTv3.setTextColor(getResources().getColor(R.color.home_red));
        }
        if (distance >= 1750) {
            signC4.setBackgroundResource(R.drawable.sign_c_red);
            signTv4.setTextColor(getResources().getColor(R.color.home_red));
        }
        if (distance >= 2250) {
            signC5.setBackgroundResource(R.drawable.sign_c_red);
            signTv5.setTextColor(getResources().getColor(R.color.home_red));
        }
        if (distance >= 2750) {
            signC6.setBackgroundResource(R.drawable.sign_c_red);
            signTv6.setTextColor(getResources().getColor(R.color.home_red));
        }
        if (distance >= 3250) {
            signC7.setBackgroundResource(R.drawable.sign_c_red);
            signTv7.setTextColor(getResources().getColor(R.color.home_red));
            signLocLl.setVisibility(View.INVISIBLE);
        }
        Logger.e("day==========" + day);
        Logger.e("isDraw==========" + isDraw);
        if (day == 7) {
            if (isDraw == 0) {
                //未领取
                ObjectAnimator animator = tada(signIvGift);
//            animator.setRepeatCount(ValueAnimator.INFINITE);//无限循环
                animator.setDuration(1500);
                animator.start();
                animator.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        SignAwardData();
                    }
                });
            }

        }
    }

    private void SignAwardData() {
        showLoading();
        mPresenter.SignAward();
    }

    private void locAnimatorFirst() {
        ObjectAnimator transXAnim = ObjectAnimator.ofFloat(signLocLl, "translationX", loc_distance * (day - 2), loc_distance * (day - 1));//横向平移动画
        transXAnim.setDuration(500);
        transXAnim.start();
    }

    public static ObjectAnimator tada(View view) {
        return tada(view, 1f);
    }

    public static ObjectAnimator tada(View view, float shakeFactor) {

        PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofKeyframe(View.SCALE_X,
                Keyframe.ofFloat(0f, 1f),
                Keyframe.ofFloat(.1f, .9f),
                Keyframe.ofFloat(.2f, .9f),
                Keyframe.ofFloat(.3f, 1.1f),
                Keyframe.ofFloat(.4f, 1.1f),
                Keyframe.ofFloat(.5f, 1.1f),
                Keyframe.ofFloat(.6f, 1.1f),
                Keyframe.ofFloat(.7f, 1.1f),
                Keyframe.ofFloat(.8f, 1.1f),
                Keyframe.ofFloat(.9f, 1.1f),
                Keyframe.ofFloat(1f, 1f)
        );

        PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofKeyframe(View.SCALE_Y,
                Keyframe.ofFloat(0f, 1f),
                Keyframe.ofFloat(.1f, .9f),
                Keyframe.ofFloat(.2f, .9f),
                Keyframe.ofFloat(.3f, 1.1f),
                Keyframe.ofFloat(.4f, 1.1f),
                Keyframe.ofFloat(.5f, 1.1f),
                Keyframe.ofFloat(.6f, 1.1f),
                Keyframe.ofFloat(.7f, 1.1f),
                Keyframe.ofFloat(.8f, 1.1f),
                Keyframe.ofFloat(.9f, 1.1f),
                Keyframe.ofFloat(1f, 1f)
        );

        PropertyValuesHolder pvhRotate = PropertyValuesHolder.ofKeyframe(View.ROTATION,
                Keyframe.ofFloat(0f, 0f),
                Keyframe.ofFloat(.1f, -3f * shakeFactor),
                Keyframe.ofFloat(.2f, -3f * shakeFactor),
                Keyframe.ofFloat(.3f, 3f * shakeFactor),
                Keyframe.ofFloat(.4f, -3f * shakeFactor),
                Keyframe.ofFloat(.5f, 3f * shakeFactor),
                Keyframe.ofFloat(.6f, -3f * shakeFactor),
                Keyframe.ofFloat(.7f, 3f * shakeFactor),
                Keyframe.ofFloat(.8f, -3f * shakeFactor),
                Keyframe.ofFloat(.9f, 3f * shakeFactor),
                Keyframe.ofFloat(1f, 0)
        );

        return ObjectAnimator.ofPropertyValuesHolder(view, pvhScaleX, pvhScaleY, pvhRotate).
                setDuration(1000);
    }

    private void locAnimator() {
        ObjectAnimator transXAnim = ObjectAnimator.ofFloat(signLocLl, "translationX", loc_distance * (day - 1), loc_distance * (day));//横向平移动画
        transXAnim.setDuration(500);
        transXAnim.start();
    }

    private void startTime(final int time) {
        Observable.interval(0, 5, TimeUnit.MILLISECONDS)//设置0延迟
                .take(time)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())// 由于interval默认在新线程，所以我们应该切回主线程
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        addDisposable(d);
                    }

                    @Override
                    public void onNext(@NonNull Long aLong) {
                        if (distance >= 3250) {
                            signC7.setBackgroundResource(R.drawable.sign_c_red);
                            signTv7.setTextColor(0xfff2383b);
                        }
                        if (distance >= 3000) {
                            signLocLl.setVisibility(View.INVISIBLE);
                        }
                        distance += 5;
                        signPb.setProgress(distance);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onComplete() {
                        initSign();
                    }
                });
    }

    //签到分享弹窗
    private void showShareGoodsPop() {
        if (shareSignPopUp == null) {
            shareSignPopUp = new ShareSignPopUp(this);
            shareSignPopUp.showGoodsSharePopUp(signTitle);
        } else {
            shareSignPopUp.showGoodsSharePopUp(signTitle);
        }
    }


    private void openGiftDialog(SignAwardBean entity) {
        giftDialog = new WinningCouponDialog(mActivity, R.style.BabyDialog,

                R.layout.module_mine_dialog_winning_coupon);
        View rootView = LayoutInflater.from(mActivity).inflate(R.layout.module_mine_dialog_winning_coupon, null);
        ImageView sign_back = rootView.findViewById(R.id.winning_dialog_finish);//取消
        TextView sign_coupon = rootView.findViewById(R.id.winning_dialog_text_coupon);//我的优惠券
        TextView sign_share = rootView.findViewById(R.id.winning_dialog_share);//分享
        TextView sign_goods_name = rootView.findViewById(R.id.winning_dialog_text_name);//商品名称
        TextView sign_goods_price = rootView.findViewById(R.id.winning_dialog_text_discount_money);//商品原价
        ImageView sign_goods_img = rootView.findViewById(R.id.winning_dialog_goods_img);//商品图片
        ImageView image = rootView.findViewById(R.id.winning_bg);

        sign_goods_name.setText(entity.getPrize().getTitle());

        RxTextTool.getBuilder("")
                .append(entity.getPrize().getPrice())
                .setStrikethrough()
                .into(sign_goods_price);

        GlideApp.with(SignActivity.this)
                .load(entity.getPrize().getImage())
                .placeholder(R.mipmap.image_default)
                .error(R.mipmap.image_default)
                .into(sign_goods_img);


        sign_back.setOnClickListener(v -> giftDialog.dismiss());

        sign_coupon.setOnClickListener(v -> {
            giftDialog.dismiss();
            RouterCommonUtils.startNoParameterActivity(RouterIntentConstant.MODULE_SHOPPING_COUPON);
        });

        sign_share.setOnClickListener(v -> {
            giftDialog.dismiss();
            if (!WXUtils.getInstance().isWxInstalledAndSurported(SignActivity.this)) {
                WpToast.l(SignActivity.this, "请先安装微信客户端!");
            }else {
                showShareGoodsPop();
            }
        });

        giftDialog.show();
        //动画 不能放在Dialog里面
        ObjectAnimator a = ObjectAnimator.ofFloat(image, "scaleY", 0f, 1.5f, 1f);
        ObjectAnimator b = ObjectAnimator.ofFloat(image, "scaleX", 0f, 1.5f, 1f);
        AnimatorSet set = new AnimatorSet();
        set.play(a).with(b);
        set.setDuration(500);
        set.start();

        giftDialog.setContentView(rootView);

    }

    private void openChestDialog() {
        final ChestDialog chestDialog = new ChestDialog(SignActivity.this);
        View rootView = LayoutInflater.from(SignActivity.this).inflate(R.layout.module_mine_dialog_chest, null);
        ImageView chest_back = (ImageView) rootView.findViewById(R.id.sign_chest_back);
        TextView chest_day = (TextView) rootView.findViewById(R.id.sign_chest_day);
        chest_day.setText((7 - day) + "");
        chest_back.setOnClickListener(v -> chestDialog.dismiss());
        chestDialog.show();
        chestDialog.setContentView(rootView);
    }

    private void toWebView(String url, String title) {
        Intent intent = new Intent(mActivity, BaseX5WebActivity.class);
        intent.putExtra("url", url);
        intent.putExtra("title", title);
        startActivity(intent);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        dispose();
    }

    private void addDisposable(Disposable disposable) {
        if (compositeDisposable == null) {
            compositeDisposable = new CompositeDisposable();
        }
        compositeDisposable.add(disposable);
    }

    private void dispose() {
        if (compositeDisposable != null) {
            compositeDisposable.dispose();
        }
    }

    @OnClick(R2.id.sign_back)
    public void backClick(View view) {
        finish();
    }

    @OnClick(R2.id.sign_detail)
    public void detailClick(View view) {
        String base_url = "http://api2.shequren.cn/";
        String url = base_url + "index.php?m=Home&c=Topic&a=index&id=13";
        toWebView(url, "签到规则");
    }

    @OnClick(R2.id.sign_iv_gift)
    public void giftClick(View view) {
        if (day < 7) {
            //弹出不可领取的弹框,把Day传进去
            openChestDialog();
        } else {
            SignAwardData();
        }
    }

    @OnClick(R2.id.sign_red_img1)
    public void red1Click(View view) {
        signRedImg1.setImageResource(R.drawable.sign_ani);
        AnimationDrawable animationDrawable1 = (AnimationDrawable) signRedImg1.getDrawable();
        animationDrawable1.start();
    }

    @OnClick(R2.id.sign_red_img2)
    public void red2Click(View view) {
        signRedImg2.setImageResource(R.drawable.sign_ani);
        AnimationDrawable animationDrawable2 = (AnimationDrawable) signRedImg2.getDrawable();
        animationDrawable2.start();
    }

    @OnClick(R2.id.sign_red_img3)
    public void red3Click(View view) {
        signRedImg3.setImageResource(R.drawable.sign_ani);
        AnimationDrawable animationDrawable3 = (AnimationDrawable) signRedImg3.getDrawable();
        animationDrawable3.start();
    }

    @OnClick(R2.id.sign_banner2)
    public void botBannerClick(View view) {
        if (null != signAdvInfo) {
            if (signAdvInfo.get(0).getType() == 1) {
                //外链
                if (!RxDataTool.isNullString(signAdvInfo.get(0).getHurl())) {
                    toWebView(signAdvInfo.get(0).getHurl(), signAdvInfo.get(0).getTitle());
                }
            } else if (signAdvInfo.get(0).getType() == 2) {
                //商品详情
                if (!RxDataTool.isNullString(signAdvInfo.get(0).getGoodsLink())) {
                    ARouter.getInstance()
                            .build(RouterIntentConstant.MODULE_SHOPPING_GOODS_DETAIL)
                            .withString("url", signAdvInfo.get(0).getGoodsLink())
                            .navigation();
                }
            }
        }
    }

}
